import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

import org.jgrapht.UndirectedGraph;
import org.jgrapht.graph.DefaultEdge;
import org.jgrapht.graph.SimpleGraph;


public class ReadGraph {

	public static UndirectedGraph<String, DefaultEdge> readInGraph(String fileName){
		UndirectedGraph<String, DefaultEdge> graph = new SimpleGraph<String, DefaultEdge>(DefaultEdge.class);
		Scanner read = null;
		int vexNum = 0;
		try{
			read = new Scanner(new File(fileName));
		} catch(FileNotFoundException e){
			e.printStackTrace();
		}
		if(read.hasNextInt()){
			vexNum = read.nextInt();
		}
		read.nextLine();
		
		//Add vertex to the graph
		for(int i = 0; i < vexNum; i++){
			String v = " " + i;
			graph.addVertex(v);
		}
		
		
		String line;
		String[] lineToken;
		while(read.hasNextLine()){
			line = read.nextLine();
			lineToken = line.split(" ");
			int size = lineToken.length;
			String v1 = " " + lineToken[0];
			String v2;
			for(int i = 1; i < size; i++){
				v2 = " " + lineToken[i];
				graph.addEdge(v1, v2);
			}
		}
		read.close();
		return graph;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
	}

}
